package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.Follow;
import com.dragon.repository.entity.PaymentContract;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * dragon Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-06-20
 */
@Mapper
public interface FollowMapper extends BaseMapper<Follow> {

    /**
     * 分页查询
     * @param followPage
     * @param wrapper
     * @return
     */
    @Select("" +
            "SELECT M.* FROM " +
            " (SELECT a.*,b.customer_name AS customerName FROM dragon_follow a " +
            " LEFT JOIN dragon_customer b ON a.customer_id = b.id )M " +
            "${ew.customSqlSegment}")
    Page<Follow> selectFollowPage(Page<Follow> followPage, @Param(Constants.WRAPPER) QueryWrapper<Follow> wrapper);

    @Select("SELECT M.* FROM " +
            " (SELECT a.*,b.customer_name AS customerName FROM dragon_follow a " +
            " LEFT JOIN dragon_customer b ON a.customer_id = b.id )M " +
            " WHERE 1=1 AND M.id = #{id} " )
    Follow listById(Integer id);

    @Select("SELECT * FROM dragon_follow a " +
            "LEFT JOIN dragon_customer c ON a.customer_id = c.id " +
            "WHERE c.id = #{id} ")
    List<Follow> selectFollowList(Integer id);
}
